package com.zh.webcommon.upload;

import lombok.Data;

import java.io.Serializable;

/**
 * @author ZH
 * @date 19:31 2022/12/8
 */
@Data
public final class FileUploadResult implements Serializable {
    private final boolean ok;
    private final String filename;
    private final String etag;
    private final String versionId;
    private final String error;
    private String url;
    private String md5;

    private FileUploadResult(boolean isOk,String filename, String etag, String versionId, String error) {
        this.ok = isOk;
        this.filename = filename;
        this.etag = etag;
        this.versionId = versionId;
        this.error = error;
    }

    public FileUploadResult linkUrl(String objectUrl) {
        if (this.url==null)
            this.url = objectUrl;
        return this;
    }

    public FileUploadResult md5(String value) {
        if (this.md5 == null)
            this.md5 = value;
        return this;
    }

    public static FileUploadResult ofSuccess(String filename,String etag,String versionId){
        return new FileUploadResult(true,filename,etag,versionId,null);
    }

    public static FileUploadResult ofFail(String filename,String error){
        return new FileUploadResult(false,filename,null,null,error);
    }

}
